'use strict';
const crypto = require("crypto");
module.exports = app => {
  const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
  // 配置（重要：一定要配置详细，一定要！！！）
  const Role = app.model.define('role', {
    id: {
      type: INTEGER(20),
      primaryKey: true,
      autoIncrement: true
    },
    rolename: {
      type: STRING(30),
      allowNull: false,
      defaultValue: '',
      comment: '权限名',
      unique: true
    },
    sortnum: {
      type: STRING(30),
      allowNull: false,
      defaultValue: '',
      comment: '排序',
    },
    menuids: {
      type: STRING(160),
      allowNull: false,
      defaultValue: '',
      comment: '权限id(用逗号分割的字符串)'
    },
    userids: {
      type: STRING(160),
      allowNull: false,
      defaultValue: '',
      comment: '用户id(用逗号分割的字符串)'
    },
    created_time: DATE,
    updated_time: DATE,
    deleted_time: DATE
  });
  // 关联关系
  Role.associate = function (models) {
    // 菜单列表
    Role.hasMany(app.model.Menus, {
      foreignKey: 'id',
      as: 'menu_id'
    });
    // 菜单列表
    Role.hasMany(app.model.User, {
      foreignKey: 'id',
      as: 'user_id'
    });
  }

  return Role;
};